package com.ian.offer;

import java.util.*;

/**
 * @author zhangyaowen
 * @date 2021/2/23 8:32 下午
 */
public class FirstUniqChar {

    public static char firstUniqChar(String s) {


        if (s.length() ==0){
            return  ' ';
        }
        HashMap<Character,Integer> map  = new LinkedHashMap<>();


        for (int i = 0; i < s.length(); i++) {
            char c =s.charAt(i);

            if (map.containsKey(c)){
                map.put(c,map.get(c)+1);
            }else{
                map.put(c,1);
            }
        }

        for (Character c: map.keySet()) {
            if (map.get(c)==1){
                return  c;
            }
        }

        return ' ';
    }

    public static void main(String[] args) {
        System.out.println(firstUniqChar("leetcode"));
    }
}
